<?php
    header("Content-type:text/html;charset=utf-8");
    if ($_POST) {
        include '../../api/config.php';
        include './comm.php';
        $json = $_POST["data"];
        $data = json_decode($json);
        $id = $data->head;
        if ($id == '1001') {
            $sql = "SELECT * FROM admin_nav WHERE flag='1'";//顶级目录
            $sql_1 = "SELECT * FROM admin_nav_list WHERE flag='1'";//子目录
        }

        if ($id == '1009') {
            $sql = "SELECT * FROM admin_nav";//顶级目录
            $sql_1 = "SELECT * FROM admin_nav_list";//子目录
        }

        if(flag($data)){
            $arr = array();
            $arr['data'] = array();
            //顶级目录
            $stmt = $conn->query($sql);
            $stmt->execute();
            $result = $stmt->setFetchMode(PDO::FETCH_ASSOC);
            $arr['data'] = $stmt->fetchAll();
            // 顶级目录
            
            $arr_1 = array();
            $arr_1['data'] = array();
            $stmt_1 = $conn->query($sql_1);
            $stmt_1->execute();
            $stmt_1->setFetchMode(PDO::FETCH_ASSOC);
            $arr_1['data'] = $stmt_1->fetchAll();

            foreach ($arr['data'] as $k => $v) {
                $arr['data'][$k]['list'] = array();
                foreach ($arr_1['data'] as $k1 => $v1) {
                    if ($arr_1['data'][$k1]['indexs'] == $arr['data'][$k]['Id']) {
                        array_push($arr['data'][$k]['list'], $v1);
                    }
                }
            }// 关联目录

            if ($arr['data']) {
                echo get_msg('200','操作成功~',false,$arr['data']);
            } else {
                echo get_msg('400','数据异常~',false,false);
            }
        }else{
            echo get_msg('500','权限不足~','../index.html',false);
        };
        $conn = null;
    } else {
        echo "<script>\r\n    window.location.href = '../../';\r\n    </script>";
    }